package de.clapp.client.musicbox.filter;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JTextField;
import javax.swing.table.TableRowSorter;

import de.clapp.client.musicbox.MusicBoxTableModel;
import de.clapp.panels.MyPanel;

@SuppressWarnings("serial")
public class MusicBoxFilterPanel extends MyPanel
{
    public MusicBoxFilterPanel(MusicBoxTableModel tableModel, TableRowSorter<MusicBoxTableModel> sorter)
    {
        this.setOpaque(true);

        this.setLayout(new GridLayout(1, 0, 5, 5));
        this.setBackground(new Color(240, 245, 250));

        MusicBoxFilterModel filterModel = new MusicBoxFilterModel(4, sorter);
        
        JTextField tf = new JTextField("Interpret");
        tf.getDocument().addDocumentListener(new MusicBoxFilterDocumentListener(tf, 0, filterModel));
        tf.addFocusListener(new RemoveInitialTextFocusListener(tf, "Interpret"));
        this.add(tf);
        
        tf = new JTextField("Album");
        tf.getDocument().addDocumentListener(new MusicBoxFilterDocumentListener(tf, 1, filterModel));
        tf.addFocusListener(new RemoveInitialTextFocusListener(tf, "Album"));
        this.add(tf);
        
        tf = new JTextField("Titel");
        tf.getDocument().addDocumentListener(new MusicBoxFilterDocumentListener(tf, 2, filterModel));
        tf.addFocusListener(new RemoveInitialTextFocusListener(tf, "Titel"));
        this.add(tf);
        
        tf = new JTextField("Jahr");
        tf.getDocument().addDocumentListener(new MusicBoxFilterDocumentListener(tf, 3, filterModel));
        tf.addFocusListener(new RemoveInitialTextFocusListener(tf, "Jahr"));
        this.add(tf);
        
        tf = new JTextField("Votes");
        tf.getDocument().addDocumentListener(new MusicBoxFilterDocumentListener(tf, 4, filterModel));
        tf.addFocusListener(new RemoveInitialTextFocusListener(tf, "Votes"));
        this.add(tf);
    }
}
